package labox.innovation.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import labox.innovation.config.Config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GMAudit {
	static {
		new File("log/GMAudit").mkdirs();
	}

	private static final Logger _log = LoggerFactory.getLogger(GMAudit.class.getName());

	private static final SimpleDateFormat _formatter = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");

	public static void auditGMAction(String gmName, String action, String target, String params) {
		String today = _formatter.format(new Date());

		FileWriter save = null;
		try {
			File file = new File("log/GMAudit/" + gmName + ".txt");
			save = new FileWriter(file, true);

			String out = (today + ">" + gmName + ">" + action + ">" + target + ">" + params + "\r\n");
			save.write(out);
		} catch (IOException e) {
			_log.error("GMAudit for GM " + gmName + " could not be saved: ", Config.SERVER_ID,e);
		} finally {
			try {
				save.close();
			} catch (Exception e) {
			}
		}
	}

	public static void auditGMAction(String gmName, String action, String target) {
		auditGMAction(gmName, action, target, "");
	}
}